package com.flow.asyncflow.test;


import com.flow.asyncflow.core.core.AsyncFlowManager;
import com.flow.asyncflow.core.entity.core.AsyncFlowResponse;
import com.flow.asyncflow.core.utils.threadpool.ThreadPoolExecutorMain;
import com.flow.asyncflow.test.AsyncFlow.Context.plusasyncflowtest.PlusAsyncFlowTestContext;
import com.flow.asyncflow.test.AsyncFlow.Enum.plusasyncflowtest.PlusAsyncFlowTestOperatorEnum;
import com.flow.asyncflow.test.AsyncFlow.Model.plusasyncflowtest.PlusAsyncFlowTestRequest;
import com.flow.asyncflow.test.AsyncFlow.Model.plusasyncflowtest.PlusAsyncFlowTestResponse;
import com.flow.asyncflow.test.Manager.asyncflowtest.PlusAsyncFlowTestManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.concurrent.ExecutorService;

@RestController
@RequestMapping("/AsyncFlowTest")
public class AsyncFlowTestController {


    @Autowired
    private PlusAsyncFlowTestManager plusAsyncFlowTestManager;

    @GetMapping("Test")
    public void test() {
        StopWatch sw = new StopWatch();
        sw.start("第一步");
        PlusAsyncFlowTestRequest request = new PlusAsyncFlowTestRequest("请求参数");
        request.setBusinessSerialId(LocalDateTime.now().toString());
        request.setOperateName("测试");
        request.setOperateNo("110");
        request.setSourceDes("测试请求");

        PlusAsyncFlowTestResponse response ;
        PlusAsyncFlowTestOperatorEnum plusAsyncFlowTestOperatorEnum = PlusAsyncFlowTestOperatorEnum.PlusAsyncFlowTest;

        sw.stop();
        long s1 = sw.getTotalTimeMillis();
        sw.start("第二步");
        request.setReqTypeEnumName("ccc");
        ThreadPoolExecutorMain.getCustomThreadPoolExecutor().execute(()->{
            PlusAsyncFlowTestResponse     response1 = plusAsyncFlowTestManager.exec(request, PlusAsyncFlowTestOperatorEnum.PlusAsyncFlowTest, PlusAsyncFlowTestResponse.class, PlusAsyncFlowTestContext.class);
        });
        ThreadPoolExecutorMain.getCustomThreadPoolExecutor().execute(()->{
            PlusAsyncFlowTestResponse    response2 = plusAsyncFlowTestManager.exec(request, PlusAsyncFlowTestOperatorEnum.PlusAsyncFlowTest, PlusAsyncFlowTestResponse.class, PlusAsyncFlowTestContext.class);
        });
        //response = plusAsyncFlowTestManager.exec(request, PlusAsyncFlowTestOperatorEnum.PlusAsyncFlowTest, PlusAsyncFlowTestResponse.class, PlusAsyncFlowTestContext.class);

        sw.stop();
        long s2 = sw.getTotalTimeMillis();
        //response=asyncFlowPlusResponse.getRes();
        //   testAsyncFlowManager.managerExec(new TestAsyncFlowRequest("请求参数"), PlusAsyncFlowTestOperatorEnum.PlusAsyncFlowTest);
        System.out.println(s1 + "####" + s2);

    }
}
